package chapter_09.stack;


class FixedStack implements IntStack {
	private int stck[];
	private int tos;
	
	FixedStack(int size) {
		stck = new int[size];
		tos = -1;
	}
	
	public void push(int item) {
		if (tos == stck.length - 1)
			System.out.println("Stack is full.");
		else
			stck[++tos] = item;
	}
	
	public int pop() {
		if (tos < 0) {
			System.out.println("Stack underflow.");
			return 0;
		}
		else
			return stck[tos--];
	}
	
	public static void main(String[] args) {
		FixedStack mystack = new FixedStack(5);
		System.out.print("Push:");
		for (int i = 0; i < 5; i++)
			mystack.push(i);
		System.out.print("Pop:");
		for (int i = 0; i < 5; i++)
			System.out.println(mystack.pop());
	}
}
